﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Core.Log;

namespace Core.Xml.Ogc.Ows
{
    /// <summary>
    /// The ServiceProvider section of a service metadata document contains metadata about the 
    /// organization operating this server.The contents and organization of this section should
    /// be the same for all OWSs. The ServiceProvider section shall include the parameters and 
    /// parts describe in Figure 5 and specified in Table 12.
    /// 
    /// [cite : OGC 06-121r9, OGC Web Services Common Standard, Version: 2.0.0, 7.4.5]
    /// </summary>
    class ServiceProvider : IXmlIsland
    {
        /// <summary>
        /// Unique identifier for service provider organization
        /// [cite : OGC 06-121r9, OGC Web Services Common Standard, Version: 2.0.0, Table 12]
        /// </summary>
        public string ProviderName { get; set; }

        /// <summary>
        /// (OPTIONAL)Reference to the most relevant web site of the service provider
        /// [cite : OGC 06-121r9, OGC Web Services Common Standard, Version: 2.0.0, Table 12]
        /// 
        /// See CI_OnlineResource class in ISO 19115
        /// </summary>
        public OnlineResourceType ProviderSite { get; set; }

        public ContactType ServiceContact { get; set; }

        public XElement CreateXElement()
        {
            if (String.IsNullOrEmpty(ProviderName))
            {
                Logger logger = Logger.GetInstance();
                logger.Add(new BasicLog(LogPriority.WARNING, "The ProviderName of the ServiceProvider must not be left empty according to the standards."));
            }
            XElement serviceProvider = new XElement(Namespaces.OWS + "ServiceProvider");

            serviceProvider.Add(new XElement(Namespaces.OWS + "ProviderName", ProviderName ?? ""));
            if (ProviderSite != null)
                serviceProvider.Add(ProviderSite.CreateXElement(Namespaces.OWS + "ProviderSite"));

            if (ServiceContact != null)
                serviceProvider.Add(ServiceContact.CreateXElement(Namespaces.OWS + "ServiceContact"));

            return serviceProvider;
        }
    }
}
